package demo.practice.top100;

import demo.practice.TreeNode;

public class P617 {

    public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
        return merge(root1, root2);
    }

    public TreeNode merge(TreeNode root1, TreeNode root2) {
        if (root1 == null && root2 == null) {
            return null;
        }
        if (root1 != null && root2 != null) {
            root1.left = merge(root1.left, root2.left);
            root1.right = merge(root1.right, root2.right);
            root1.val=root1.val+root2.val;
            return root1;
        }
        return root1 != null ? root1 : root2;
    }
}
